﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TVA
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void ttcChanged(object sender, TextChangedEventArgs e)
        {
            ttcChanged();
        }

        private void ttcChanged()
        {
            if (String.IsNullOrEmpty(this.tvaChoice.Text))
            {
                MessageBox.Show("il faut d'abord remplir le taux de TVA", "error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                if (!String.IsNullOrEmpty(this.ttc.Text))
                {
                    Double taux = Double.Parse(this.tvaChoice.Text);
                    Double ttc = Double.Parse(this.ttc.Text);
                    Double ht = ttc / (1 + taux / 100);
                    this.ht.Text = ht.ToString();
                }
            }
        }

        private void htChanged(object sender, TextChangedEventArgs e)
        {
            htChanged();

        }

        private void htChanged()
        {
            if (String.IsNullOrEmpty(this.tvaChoice.Text))
            {
                MessageBox.Show("il faut d'abord remplir le taux de TVA", "error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                if (!String.IsNullOrEmpty(this.ht.Text))
                {
                    Double taux = Double.Parse(this.tvaChoice.Text);
                    Double ht = Double.Parse(this.ht.Text);
                    Double ttc = ht * (1 + taux / 100);
                    this.ttc.Text = ttc.ToString();
                }
            }
        }

        private void ht_Changed(object sender, RoutedEventArgs e)
        {
            htChanged();
        }

        private void ttcChanged(object sender, RoutedEventArgs e)
        {
            ttcChanged();
        }
    }
}
